package logic

import (
	"cartsrv/cartrpc"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsAddLogic) GoodsAdd(req *types.GoodsAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.CartRpc.GoodsAdd(l.ctx, &cartrpc.GoodsAddRequest{
		GoodsTitle: req.GoodsTitle,
		GoodsStock: int64(req.GoodsStock),
		GoodsPrice: float32(req.GoodsPrice),
		GoodsCover: req.GoodsCover,
		Status:     req.Status,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: "商品不存在",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "商品添加成功",
		Data:    add,
	}, nil
}
